package com.spring.boot.controller;

import com.spring.boot.entity.Insurance;
import com.spring.boot.entity.User;
import com.spring.boot.service.InsuranceService;
import com.spring.boot.vo.QueryRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: ZTQ
 * @Date: 2021/01/01 17:26
 * @Description: TODO 险种管理 控制器
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/insurance")
public class InsuranceController {
    @Autowired
    private InsuranceService insuranceService;

    /**
     * @param insurance 险种对象
     * @description: 添加险种
     */
    @PostMapping(value = "/addInsurance", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> addInsurance(@RequestBody Insurance insurance) {
        //调用险种service层的addInsurance方法，进行新增险种操作
        Map<String, Object> stringObjectMap = insuranceService.addInsurance(insurance);
        //返回数据信息
        return stringObjectMap;
    }


    /**
     * @param insurance 险种对象
     * @description: 修改险种
     */
    @PostMapping(value = "/updateInsurance", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> updateInsurance(@RequestBody Insurance insurance) {
        //调用险种service层的updateInsurance方法，进行修改险种操作
        Map<String, Object> stringObjectMap = insuranceService.updateInsurance(insurance);
        //返回数据信息
        return stringObjectMap;
    }

    /**
     * @param insuranceId 险种id
     * @description: 批量删除险种
     */
    @GetMapping(value = "/deleteBatchIdsInsurance", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> deleteBatchIdsInsurance(@RequestParam String insuranceId) {
        //调用险种service层的deleteBatchIdsInsurance方法，进行修改险种操作
        Map<String, Object> stringObjectMap = insuranceService.deleteBatchIdsInsurance(insuranceId);
        //返回数据信息
        return stringObjectMap;
    }


    /**
     * @param insurance 险种对象
     * @description: 根据关键字 筛选查询险种信息
     */
    @GetMapping(value = "/getInsuranceList",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> getUserList(QueryRequest queryRequest, Insurance insurance){
        //调用险种service层的findInsuranceList方法，进行根据关键字进行筛选查询操作
        Map<String, Object> insuranceList = insuranceService.findInsuranceList(queryRequest, insurance);
        //返回数据信息
        return insuranceList;
    }

    /**
     * @description: 查询险种列表
     */
    @GetMapping(value = "/getInsuranceAllList",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> getInsuranceAllList(){
        //调用险种service层的findInsuranceList方法，进行根据关键字进行筛选查询操作
        Map<String, Object> insuranceAllList = insuranceService.findInsuranceAllList();
        //返回数据信息
        return insuranceAllList;
    }
}
